package com.cartoonrabbit.controller;


import com.cartoonrabbit.service.IQRCodeService;
import com.cartoonrabbit.vo.RespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

@RestController
@RequestMapping("/QRcode")
@Api(tags = "小程序二维码相关接口")
public class QRCodeController {

    @Autowired
    private IQRCodeService qrCodeService;

    @ApiOperation(value = "获取UnlimitedQRCode")
    @GetMapping("/unlimitedQRCode")
    @PreAuthorize("@ss.permitAll()")
    public RespBean getUnlimitedQRCode(Principal principal){
        if (ObjectUtils.isEmpty(principal)||ObjectUtils.isEmpty(principal.getName())){
            return RespBean.fail(401,"用户为授权，请重新登录");
        }
        return qrCodeService.getUnlimitedQRCode(principal.getName());
    }
}
